package util;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;

import java.util.HashMap;

public class MyXMLReader extends XMLFilterImpl
{
    String defaultNameSpace;
    String type;
    int index = 5;
    HashMap <String, String> extraNameSpaceMap = new HashMap <>();
    public MyXMLReader(String defaultNameSpace, String type)
    {
        this.defaultNameSpace = defaultNameSpace;
        this.type = type;
    }

    @Override
    public void startPrefixMapping(String prefix, String uri) throws SAXException
    {
        super.startPrefixMapping(prefix, uri);
    }

    @Override
    public void endPrefixMapping(String prefix) throws SAXException
    {
        super.endPrefixMapping(prefix);
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
    {
        if (uri.equals(defaultNameSpace) && localName.equals(type))
        {
            qName = "ns3:" + qName;
        }
        super.startElement(uri, localName, qName, atts);
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException
    {
        if (uri.equals(defaultNameSpace) && localName.equals(type))
        {
            qName = "ns3:" + qName;
        }
        super.endElement(uri, localName, qName);
    }
}
